﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DBEngine.Elements;
using System.Data;
using System.Data.SqlClient;

namespace DBEngine.Tables
{
    class GlassesOrderTable : OrdersTable
    {
        protected static Dictionary<Enum, SqlDbType> TABLE_FIELDS;
        static GlassesOrderTable()
        {
            TABLE_FIELDS = new Dictionary<Enum, SqlDbType>();

            foreach (EyeGlasses.Fields glassesField in Enum.GetValues(typeof(EyeGlasses.Fields)))
            {
                if(glassesField == EyeGlasses.Fields.Frame)
                    TABLE_FIELDS.Add(glassesField, SqlDbType.VarChar);
                else
                    TABLE_FIELDS.Add(glassesField, SqlDbType.Bit);
            }
        }

        internal GlassesOrderTable()
            : base("GlassesOrder", TABLE_FIELDS){}

        override protected OrderElement ReadOrderElemnt(SqlDataReader reader)
        {
            OrderElement retval = new EyeGlasses();
            foreach (EyeGlasses.Fields glassesField in Enum.GetValues(typeof(EyeGlasses.Fields)))
            {
                Object o = reader[glassesField.ToString()];
                if (glassesField == EyeGlasses.Fields.Frame)
                    retval[glassesField] = (string)o;
                else
                    retval[glassesField] = Convert.ToBoolean(o);
            }

            return retval;
        }

    }
}
